package com.webex.ta.hydra.gui;

import com.webex.ta.hydra.gui.action.ActionRouter;
import com.webex.ta.hydra.gui.menu.ContextMenuProvider;

import javax.swing.*;

/**
 * Created by Cisco WebEx.
 * User: vegaz
 * Date: 2010-8-20
 * Time: 9:02:16
 */
public class MenuFactory {
    private static ContextMenuProvider contextMenuProvider = new ContextMenuProvider();
    public static JPopupMenu createContextMenu() {
        JMenu menu = new JMenu();
        contextMenuProvider.update(menu);
        return menu.getPopupMenu();

    }

    public static JMenuItem makeMenuItem(String label, String name, String actionCommand) {
        JMenuItem newMenuChoice = new JMenuItem(label);
        newMenuChoice.setName(name);
        newMenuChoice.addActionListener(ActionRouter.getInstance());
        if (actionCommand != null) {
            newMenuChoice.setActionCommand(actionCommand);
        }

        return newMenuChoice;
    }

    public static JMenuItem makeMenuItem(String label, int mnemonic, String name, String actionCommand) {
        JMenuItem newMenuChoice = new JMenuItem(label, mnemonic);
        newMenuChoice.setName(name);
        newMenuChoice.addActionListener(ActionRouter.getInstance());
        if (actionCommand != null) {
            newMenuChoice.setActionCommand(actionCommand);
        }

        return newMenuChoice;
    }


    public static JMenuItem makeMenuItem(String label, String name, String actionCommand, KeyStroke accel) {
        JMenuItem item = makeMenuItem(label, name, actionCommand);
        item.setAccelerator(accel);
        return item;
    }

    public static JMenuItem makeMenuItem(String label, int mnemonic, String name, String actionCommand, KeyStroke accel) {
        JMenuItem item = makeMenuItem(label, mnemonic, name, actionCommand);
        item.setAccelerator(accel);
        return item;
    }

    public static JMenuItem makeMenuItem(String label, String name, String actionCommand, KeyStroke accel, Icon icon) {
        JMenuItem item = makeMenuItem(label, name, actionCommand, accel);
        item.setIcon(icon);
        return item;
    }

    public static JMenuItem makeMenuItem(String label, int mnemonic, String name, String actionCommand, KeyStroke accel, Icon icon) {
        JMenuItem item = makeMenuItem(label, name, actionCommand, accel);
        item.setMnemonic(mnemonic);
        item.setIcon(icon);
        return item;
    }
}
